Skip to content

[T2407] FIX : Correct opportunities count calculation - #2115

Open
Ylulu71D wants to merge 1 commit into
18.0from
T2407-FIX-Correct-opportunities-count-calculation
Open

[T2407] FIX : Correct opportunities count calculation#2115
Ylulu71D wants to merge 1 commit into
18.0from
T2407-FIX-Correct-opportunities-count-calculation

Conversation

@Ylulu71D

Copy link
Copy Markdown

Goal

The goal of this PR is to fix an inaccurate opportunity counter displayed on res.partner records.

History & Issue:

November 2025: A custom adjustment was introduced to count all historical opportunities (ongoing or archived) linked to a customer—whether an individual, a company entity, or a rollup of all individuals linked to that company.

June 2026: Following an official update to the Odoo core crm and website_crm_partner_assign add-ons, this legacy custom code began double-counting archived records. This caused the UI counter to unexpectedly inflate (e.g., displaying a count of 5 instead of 3 for a partner with 1 active and 2 archived opportunities).

This PR corrects the calculation by removing the redundant logic, ensuring the pipeline overview displays accurate totals for users.


Technical Aspects

The bug stemmed from a redundancy in the Method Resolution Order (MRO) inheritance chain of the _compute_opportunity_count function across three modules: Core crm, website_crm_partner_assign, and the compassion custom module crm_compassion.

  • The Core Behavior: Standard Odoo crm already calculates a grand total of historical opportunities (both active and archived) out of the box using with_context(active_test=False). Furthermore, it natively handles the hierarchical roll-up, meaning a member's opportunities automatically bubble up to their parent company via a child_of operator search.
  • The Root Cause: The crm_compassion module contained a redundant override that explicitly queried archived opportunities ('active', '=', False) and forcefully appended them to the existing tally using +=. Because Core Odoo had already counted these archived records in step one, this custom logic caused them to be double-counted.
  • The Solution: The redundant _compute_opportunity_count method has been entirely removed from crm_compassion. This allows Odoo's native inheritance chain to accurately resolve the count while fully preserving the official intermediate logic website_crm_partner_assign and the native member-to-company hierarchical roll-up.

Misc

Testing & Verification Steps

  1. Navigate to a partner/customer record with 3 active opportunities (the UI counter should display 3).
  2. Archive 2 of those opportunities (moving them to "Lost" or archiving them manually).
  3. Refresh and verify the partner view: The smart button counter should accurately remain at 3 (representing 1 active + 2 archived) instead of inflating to 5.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the custom _compute_opportunity_count method from the res.partner model in crm_compassion/models/res_partner.py. I have no feedback to provide on these changes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@Ylulu71D
Ylulu71D marked this pull request as ready for review July 20, 2026 14:32
@Ylulu71D
Ylulu71D requested a review from ecino July 20, 2026 14:32
@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

Safe to merge with minimal risk.

The change is a focused deletion of redundant counting logic, and no issues were identified in the changed file.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • A runtime blocker was identified during validation, showing missing odoo-bin, ModuleNotFoundError for import odoo, and unavailable pg_isready in the runtime availability log.
  • The before-state confirms the initial res_partner.py state included _compute_opportunity_count calling super() and adding crm.lead().search_count into partner.opportunity_count.
  • The after-state confirms the current res_partner.py has zero matches for the local opportunity counter/archive patterns and exits successfully.
  • A syntax proof shows Python compiled successfully with python3 -m py_compile and exit code 0.

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
crm_compassion/models/res_partner.py Removed the custom _compute_opportunity_count override so inherited CRM logic computes opportunity totals without double-counting archived leads.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant UI as Partner smart button
participant Partner as res.partner
participant WebsiteCRM as website_crm_partner_assign
participant CRM as Odoo crm
participant Lead as crm.lead

UI->>Partner: read opportunity_count
Partner->>WebsiteCRM: _compute_opportunity_count()
WebsiteCRM->>CRM: super()
CRM->>Lead: count opportunities with archived included
Lead-->>CRM: historical total
CRM-->>WebsiteCRM: computed count
WebsiteCRM-->>Partner: inherited count
Partner-->>UI: "accurate total without custom archived += count"
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant UI as Partner smart button
participant Partner as res.partner
participant WebsiteCRM as website_crm_partner_assign
participant CRM as Odoo crm
participant Lead as crm.lead

UI->>Partner: read opportunity_count
Partner->>WebsiteCRM: _compute_opportunity_count()
WebsiteCRM->>CRM: super()
CRM->>Lead: count opportunities with archived included
Lead-->>CRM: historical total
CRM-->>WebsiteCRM: computed count
WebsiteCRM-->>Partner: inherited count
Partner-->>UI: "accurate total without custom archived += count"
Loading

Reviews (1): Last reviewed commit: "[T2407] FIX : Correct opportunities coun..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant